﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    $(function () {
        InitialPage();
        GetGrid();
    });

    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_PollingBussiness/GetListJson",
            datatype: "json",
            height: $(window).height() - 165.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "编号", name: "Code", index: "Code", width: 150, align: "left" },
                { label: "名称", name: "Name", index: "Name", width: 150, align: "left" },
                { label: "绩效分", name: "Goals", index: "Goals", width: 150, align: "left" },
                { label: "说明", name: "Memo", index: "Memo", width: 150, align: "left" }
            ],
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'CreateDate',
            sortorder: 'desc',
            viewrecords: true,
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            subGrid: true,
            subGridRowExpanded: function (subgrid_id, row_id) {
                
                var _keyValue = $("#gridTable").jqGrid('getRowData', row_id)['Id'];
                var subgrid_table_id = subgrid_id + "_t";
                var subhtml = "";
                subhtml += '<div><table id="' + subgrid_table_id + '"></table></table></div>';
                $("#" + subgrid_id).html(subhtml);
                $("#" + subgrid_table_id).jqGrid({
                    url: "../../PropertyManage/CS_PollingBussiness/GetRelationListJson?WBPerformanceId=" + _keyValue,
                    datatype: "json",
                    height: 260,
                    autowidth: true,
                    colModel: [
                       { label: '项目主键', name: 'Id', hidden: true },
                { label: '关联表主键', name: 'OIId', hidden: true },
                { label: '对象主键', name: 'ObjectId', hidden: true },
                { label: '所属巡检专业', name: 'TypeName', width: 200, align: 'center', sortable: false },
                { label: '对象名称', name: 'ObjName', width: 200, align: 'center', sortable: false },
                { label: '对象组织机构', name: 'OrganizeId', hidden: true },
                { label: '对象地址', name: 'Address', width: 350, align: 'center', sortable: false },
                {
                    label: "标识方式", name: "FlagWay", index: "FlagWay", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "无标识"; break;
                            case 1: return "rfid芯片"; break;
                            case 2: return "条码"; break;
                            case 3: return "二维码"; break;
                            case 4: return "beacon"; break;
                            default: return "无";
                        }
                    }
                },
                { label: '对象编码', name: 'ObjCode', width: 200, align: 'center', sortable: false },
                { label: '项目名称', name: 'Name', index: 'Name', width: 200, align: 'center', sortable: false },
                { label: '编码', name: 'Code', index: 'Code', width: 200, align: 'center', sortable: false },
                { label: '执行频次', name: 'Frequency', index: 'Frequency', width: 70, align: 'center', sortable: false }
                    ],
                    rowNum: "all",
                    caption: "项目对象列表",
                    hidegrid: false,
                    shrinkToFit: false,
                    gridview: true
                });
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                url: "../../PropertyManage/CS_PollingBussiness/GetListJson",
                postData: {
                    condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                    keyword: $("#txt_Keyword").val(),
                    page: 1
                }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加工单标准',
            url: '/PropertyManage/CS_PollingBussiness/Form',
            width: "1100px",
            height: "700px",
            btn: null,
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑工单标准',
                url: '/PropertyManage/CS_PollingBussiness/Form?keyValue=' + keyValue,
                width: "1100px",
                height: "700px",
                btn: null,
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }

    //生成工单
    function btn_addInstance() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        var Memo = $("#gridTable").jqGridRowValue("Memo");
        
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '生成工单',
                url: '/PropertyManage/CS_PollingBussiness/AddBillInstance?keyValue=' + keyValue + "&Memo=" + Memo,
                width: "500px",
                height: "370px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }


    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PropertyManage/CS_PollingBussiness/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的项目！', 0);
        }
    }

    ////查看
    //function btn_preview() {
    //    var keyValue = $("#gridTable").jqGridRowValue("Id");
    //    if (checkedRow(keyValue)) {
    //        dialogOpen({
    //            id: "Form",
    //            title: '查看巡检业务明细',
    //            url: '/PropertyManage/CS_PollingBussiness/DetailForm?keyValue=' + keyValue,
    //            width: "700px",
    //            height: "450px",
    //            callBack: function (iframeId) {
    //                top.frames[iframeId].AcceptClick();
    //            }
    //        });
    //    }
    //}
 
    //管理巡检项目
    function btn_ItemDetailIndex() {
        dialogOpen({
            id: "ItemDetailIndex",
            title: '管理巡检项目',
            url: '/PropertyManage/CS_Polling/ItemDetailIndex',
            width: "1100px",
            height: "700px",
            btn: null
        });
    }

    //管理巡检内容
    function btn_ContentIndex() {
        dialogOpen({
            id: "ContentIndex",
            title: '管理巡检内容',
            url: '/PropertyManage/CS_Polling/ContentIndex',
            width: "1100px",
            height: "700px",
            btn: null
        });
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">工单标准信息</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-addInstance" class="btn btn-default" onclick="btn_addInstance()"><i class="fa fa-plus"></i>&nbsp;生成工单</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        @*<a id="lr-detail" class="btn btn-default" onclick="btn_preview()"><i class="fa fa-eye"></i>&nbsp;查看</a>*@
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <div class="btn-group">
                        <a id="lr-more" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                            <i class="fa fa-reorder"></i>&nbsp;更多设置<span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu pull-right">                        
                            <li id="lr-Item"><a onclick="btn_ItemDetailIndex()"><i></i>&nbsp;管理巡检项目</a></li>
                            <li id="lr-Content"><a onclick="btn_ContentIndex()"><i></i>&nbsp;管理巡检内容</a></li>
                        </ul>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>